#include "app/app_main.h"
#include "rtt_debug.h"

#include "cyclonetcp.h"

#define DEMO_STACK_SIZE				512
#define DEMO_BYTE_POOL_SIZE 	(20 * 1024)

static TX_BYTE_POOL byte_pool_0;

TX_THREAD thread_0;

static void thread_0_entry(ULONG thread_input);

VOID tx_application_define(VOID *first_unused_memory)
{
	CHAR *pointer = TX_NULL;

	/* Create a byte memory pool from which to allocate the thread stacks.  */
	tx_byte_pool_create(&byte_pool_0, "byte pool 0", first_unused_memory, DEMO_BYTE_POOL_SIZE);

	/* Put system definition stuff in here, e.g. thread creates and other assorted
		 create information.  */

	/* Allocate the stack for thread 0.  */
	tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

	/* Create the main thread.  */
	tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,  
					pointer, DEMO_STACK_SIZE, 
					1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
	
	cyclonetcp_init();
	
	app_http_client_thread_create(&byte_pool_0);
}

void thread_0_entry(ULONG thread_input)
{
	/* This thread simply sits in while-forever-sleep loop.  */
	while(1)
	{
		PRINTF("tick:%d\r\n",HAL_GetTick());
		
		tx_thread_sleep(10000);
	}
}

TX_BYTE_POOL* thread_get_pool(void)
{
	return &byte_pool_0;
}
